const App = {
    extends: Parent,
    methods: {
        init() {
            this.selectMyUser();

            //查询param
            var name = getParam("name");
            axios({
                method:"get",
                url:ParentUrl+"/Community/"+name
            }).then(resp => {
                this.Result = resp.data;
                if (this.Result.code===1) {
                    this.hCommunity = this.Result.data;
                }
            });
            this.searchTrendsByCommunity(name);
        },
        selectCommunity(name) {
            var _this = this;
            axios.get(ParentUrl+"/Community/"+name, ).then(resp=>{
                _this.Result = resp.data;
                if(_this.Result.code===1) {
                    _this.hCommunity = _this.Result.data;
                }
                else {
                }
            });
        },//查询社区
        searchTrendsByCommunity(name) {
            var _this = this;
            axios({
                method:"get",
                url:ParentUrl+"/Trends/5?name="+name
            }).then(resp => {
                _this.Result = resp.data;
                if(_this.Result.code === 1) {
                    _this.communityTrends=_this.Result.data;
                } else {

                }
            })
        },//查询社区动态
        addCommunityMember(communityId) {
            axios.post(ParentUrl+"/CommunityMember/"+communityId).then(resp=>{
                this.Result = resp.data;
                if(this.Result.code === 1) {
                    this.$message({
                        message: '成功加入！',
                        type: 'success'
                    });
                } else {
                    this.$message({
                        message: '加入失败！',
                        type: 'warning'
                    });
                }
            });
        },//加入社区成员
        like(trend) {
            var _this = this;
            axios.put(ParentUrl+"/Trends/1/"+trend.id).then(resp=>{
                _this.Result = resp.data;
                //成功点赞
                if (_this.Result.code===1) {
                    this.$message({
                        message: '点赞成功！',
                        type: 'success'
                    });
                    trend.likesNum++;
                }
                //取消点赞
                else if (_this.Result.code===-1) {
                    this.$message({
                        message: '已取消点赞。',
                        type: 'success'
                    });
                    trend.likesNum--;
                }
                //点赞失败
                else {
                    this.$message({
                        message: '点赞失败！',
                        type: 'warning'
                    });
                }
            });
        },//点赞
        collect(trend) {
            var _this = this;
            axios.put(ParentUrl+"/Trends/2/"+trend.id).then(resp=>{
                _this.Result = resp.data;
                //成功点赞
                if (_this.Result.code===1) {
                    this.$message({
                        message: '收藏成功！',
                        type: 'success'
                    });
                    trend.collectNum++;
                }
                //取消点赞
                else if (_this.Result.code===-1) {
                    this.$message({
                        message: '已取消收藏。',
                        type: 'success'
                    });
                    trend.collectNum--;
                }
                //点赞失败
                else {
                    this.$message({
                        message: '收藏失败！',
                        type: 'warning'
                    });
                }
            });
        },//收藏
        critiqueTrends() {
            var _this = this;
            axios.post(ParentUrl+"/Critique", _this.critique).then(resp=>{
                _this.Result = resp.data;
                if(_this.Result.code===1) {
                    _this.critiques=null;
                    _this.critiqueDialog = false;
                    this.$message({
                        showClose: true,
                        message: '评论成功！',
                        type: 'success'
                    });
                } else {
                    this.$message({
                        showClose: true,
                        message: '评论失败！',
                        type: 'warning'
                    });
                }
            })
        },//评论
        addCommunityMember(communityId) {
            axios.post(ParentUrl+"/CommunityMember/"+communityId).then(resp=>{
                this.Result = resp.data;
                if(this.Result.code === 1) {
                    this.$message({
                        message: '成功加入！',
                        type: 'success'
                    });
                } else {
                    this.$message({
                        message: '加入失败！',
                        type: 'warning'
                    });
                }
            });
        }//加入社区成员
    },
    data() {
        return {
            userInformationDialog: false,//查看用户
            critiqueDialog: false,//评论
            communityInformationDialog: false,//查看社区
            hCommunity: {},//当前页社区
            communityTrends: [],//社区动态
            hTrend: {},//需要查看的动态用户信息
            critique: {
                content: '',
                time: date.toLocaleDateString()+'/'+date.toLocaleTimeString(),
                trendsId: ''
            },//正在评论
        };
    }
};
const app = Vue.createApp(App);
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}
app.use(ElementPlus);
app.mount("#app");